package com.xz.danhuaapi.service.inner;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xz.danhuaapi.common.ErrorCode;
import com.xz.danhuaapi.exception.ThrowUtils;
import com.xz.danhuaapi.mapper.UserMapper;
import com.xz.danhuaapicommon.model.entity.User;
import com.xz.danhuaapicommon.service.InnerUserService;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;

import javax.annotation.Resource;

/**
 * @author xuzhou
 * @version 1.0
 * @createTime 2024-08-01
 * @description
 */
@DubboService
public class InnerUserServiceImpl implements InnerUserService {

    @Resource
    private UserMapper userMapper;

    /**
     * 查询数据库中是否有已经分配该密钥的用户(accessKey)
     *
     * @param accessKey
     * @return
     */
    @Override
    public User getInvokeUser(String accessKey) {
        ThrowUtils.throwIf(StringUtils.isBlank(accessKey), ErrorCode.PARAMS_ERROR);
        QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
        userQueryWrapper.eq("access_key", accessKey);
        return userMapper.selectOne(userQueryWrapper);
    }
}
